package versuch.client;

import java.util.Date;

import com.google.gwt.user.client.Cookies;

public class CookieManager {

	/**
	 * Checks if a certain cookie exists, returns true when a cookie exists 
	 * and false when it doesn't
	 * 
	 * @param identifier The identifier of the ID you want to see the cookie for
	 */
	public static boolean cookieExists() {
		if (Cookies.getCookie("EIST_POLL") != null)
			return true;
		return false;
	}
	
	/**
	 * Sets a cookie with a given ID
	 * 
	 * @param identifier The identifier of the ID you want to set the cookie for
	 */
	public static boolean setCookie()
	{
		System.out.println("Cookie set!");                      
		//Cookies.setCookie("EIST_POLL", "EIST_POLL", new Date(2147483647));
		
		Date now = new Date();
		long nowLong = now.getTime();
		nowLong = nowLong + (1000 * 60 * 60 * 24 * 7);//seven days
		now.setTime(nowLong);

		Cookies.setCookie("EIST_POLL", "sampleCookiValue", now);
		
		return true;
	}

}
